Podrick the Bot
Peter Chow | August 30 - October 13, 2020 | Python | Discord.py | Heroku | Twilio
A picture of the discord server where Podrick lives in.
The Idea
During reading week (one week break to catch up on lectures, HW, etc.) at U of T, I decided to create a Discord bot. I had this idea for a long time because I enjoy automating things. I named my bot after Podrick, a squire from Game of Thrones. At first, I attempted this project using Twilio, a cloud communication platform that can send text messages with Python. However, I later realized that in order to keep this going on forever, I needed to pay for it. Therefore, using Heroku to run the Python script on an external Linux server and Discord.py, the rewrite branch from the Discord API, I successfully created Podrick.
The Learning Process
The daily information I send consists of weather updates, COVID updates, random fun facts, and random quotes. These are done using APIs and the requests module for Python. This gave me a deeper understanding of how to use APIs to get information.
Reading the documentation on Discord.py was very confusing at first. This is because there are parameters within the functions from the modules that are somewhat confusing. As I am fairly new to Discord, it took some time to understand what channels, guilds, and roles are. I watched a full playlist of Discord.py tutorials until I started to understand what was going on. Once I understood what was going on, it all became fairly easy to me. Essentially, in order to program the bot to perform some action, there are a plethora of built-in functions that would be called when a certain event triggers it. In the code below, the function on_member_join() would perform everything within that function when a new member joins a server. The functions also take on function decorators such us @client.command() and @client.event.
As Podrick resides in a server, I added the option for my friends to subscribe to daily notifications. They can change their roles on discord to the time that they want this notification to be sent to them. The discord invite link is above.
Since the Python program is required to run continuously for the Bot to stay online, I used Heroku, an online cloud application platform that can run my scripts. Heroku is similar to Wayscript as they both run code on a Linux server somewhere in the world. Heroku is interesting because it has a CLI (Command-line interface) that we have to download and use. Here, I learned about remotes because I had to commit the source code to the Heroku remote repository, as opposed to the 'origin' remote repository which is often connected to the Github online repository.
I stumbled upon Git branches when I had to make sure that I wouldn't accidentally publish the discord bot token on Github. Since I also had to publish the code online for people to see, I decided to create a branch version where I would not show the token ID.
One difference between Wayscript and Heroku is that Heroku runs the scripts 24/7, while Wayscript will only run a script at most every hour. Thus Heroku is the perfect application to use as my discord bot will be run indefinitely.
Overall, it was a great learning experience, and although I might not make a lot of discord bots, I learned quite a lot about git.